#!/usr/bin/env python
# coding=utf-8
"""ffi简单调用示例
无痛调用c/c++代码并获得原生性能
"""
import time
from _compute import ffi, lib

a = ffi.new("int[]", [122, 116, 138, 127, 114, 107, 125, 126, 144, 109, 140, 131, 119, 118, 121, 136, 129, 128, 140, 147, 140, 115, 129, 123, 123, 125, 131, 127, 127, 140, 131, 131, 118, 139, 130, 124, 129, 150, 144, 125, 135, 123, 131, 118, 116, 140, 133, 140, 151, 119, 133, 139, 146, 139, 135, 124, 116, 119, 118, 126, 130, 133, 131, 127, 118, 117, 121, 109, 133, 115, 144, 149, 120, 125, 112, 131, 126, 140, 140, 112, 121, 141, 137, 103, 126, 124, 114, 128, 126, 133, 126, 145, 118, 130, 124, 125, 141, 137, 140, 125, 117, 108, 124, 138, 129, 152, 108, 139, 138, 111, 111, 119, 134, 144, 122, 121, 124, 114, 121, 126, 142, 110, 122, 130, 119, 120, 132, 123])
b = ffi.new("int[]", [123, 106, 148, 130, 123, 119, 124, 121, 134, 119, 143, 122, 126, 108, 119, 130, 137, 140, 150, 153, 128, 114, 144, 124, 124, 142, 131, 125, 130, 143, 119, 134, 136, 144, 136, 136, 126, 137, 139, 125, 132, 115, 135, 112, 128, 131, 126, 136, 149, 126, 115, 126, 140, 128, 141, 129, 123, 122, 127, 138, 120, 134, 131, 122, 133, 105, 127, 107, 140, 116, 153, 143, 118, 131, 111, 132, 118, 138, 136, 114, 128, 132, 131, 112, 118, 132, 108, 120, 136, 127, 119, 132, 113, 120, 127, 124, 140, 127, 151, 138, 126, 100, 131, 134, 136, 142, 116, 138, 134, 124, 108, 122, 141, 139, 129, 111, 128, 113, 123, 129, 128, 118, 124, 127, 117, 124, 145, 130])
size = ffi.cast("int", 128)
r = ffi.new("int *")
start_time = time.time()
for i in xrange(1, 1000000):
    lib.compute(a, b, size, r)
end_time = time.time()
print("loss time: {:.2f}s".format(end_time - start_time))
# print(r[0])
